package com.kaishengit.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.GoodsBackDao;
import com.kaishengit.dao.InventoryDao;
import com.kaishengit.pojo.GoodsBack;
import com.kaishengit.pojo.Inventory;

@Service
@Transactional
public class GoodsBackService {
	private GoodsBackDao goodsBackDao;
	private InventoryDao inventoryDao;
	
	public void add(GoodsBack goodsBack){
		
		Inventory inventory = inventoryDao.findByGoodsid(goodsBack.getGoods().getId());
		inventory.setNumber(inventory.getNumber() - goodsBack.getOutputnum());
		inventory.setGoods(goodsBack.getGoods());
		inventoryDao.update(inventory);
		
		goodsBackDao.add(goodsBack);
		
	}
	public List<GoodsBack> findAll(){
		return goodsBackDao.findAll();
	}
	public List<GoodsBack> findByWhere(GoodsBack goodsBack){
		return goodsBackDao.findByWhere(goodsBack);
	}
	@Autowired
	public void setGoodsBackDao(GoodsBackDao goodsBackDao) {
		this.goodsBackDao = goodsBackDao;
	}
	@Autowired
	public void setInventoryDao(InventoryDao inventoryDao) {
		this.inventoryDao = inventoryDao;
	}
	
	

}
